home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / amos / intuiextend16.lha / bonus / makelib / MakeLib_example1.amos / MakeLib_example1.amosSourceCode
AMOS Source Code  |  1980-01-04  |  1KB  |  95 lines

  1. '
  2. '  Make_Lib Example 1, showing use of: 
  3. '
  4. '  ma Malloc, ma Free All, ma AddHead, ma Next, ma Prev, ma First
  5. '  and ma Last 
  6. '
  7. '
  8.  
  9. NODES=14
  10.  
  11. ' MEM_FREE 
  12. LIST_CREATE[NODES]
  13. LIST_SHOW[Param]
  14. CLEAN_UP
  15.  
  16.  
  17. '
  18. '  Clean up routine, frees all malloc'ed memory with one ma Free All   
  19. '  command 
  20. '
  21.  
  22. Procedure CLEAN_UP
  23.     Extension_17_00D0 
  24. '  MEM_FREE
  25.    Wait Key 
  26.    Edit 
  27. End Proc
  28.  
  29. '
  30. '  Shows current free memory (chip and fast) 
  31. '
  32.  
  33. Procedure MEM_FREE
  34.    Print "CHIP: "+Str$(Chip Free)+"  FAST: "+Str$(Fast Free)
  35. End Proc
  36.  
  37. '
  38. '  Shows created list
  39. '
  40.  
  41. Procedure LIST_SHOW[LIST]
  42.  
  43.    Print "ALL NODES BEGIN --> END"
  44.  
  45.    NODE= Extension_17_00FE(LIST)
  46.  
  47.    While NODE
  48.       Print Deek(NODE+8)
  49.       NODE= Extension_17_00E2(NODE)
  50.    Wend 
  51.  
  52. '
  53. '  And same backwards! 
  54. '
  55.  
  56.    Print "ALL NODES END --> BEGIN"
  57.  
  58.    NODE= Extension_17_010E(LIST)
  59.  
  60.    While NODE
  61.       Print Deek(NODE+8)
  62.       NODE= Extension_17_00F0(NODE)
  63.    Wend 
  64.  
  65. End Proc
  66.  
  67. '
  68. '  Creates list including NODES number of nodes :) 
  69. '
  70.  
  71. Procedure LIST_CREATE[NODES]
  72.  
  73. '
  74. ' First Malloc list header (12 bytes!) 
  75. '
  76.  
  77. LIST= Extension_17_00B0(12,0)
  78. If LIST Then Extension_17_002E LIST Else CLEAN_UP
  79.  
  80. '
  81. ' Then Malloc all nodes and add them into list (Node header = 8 bytes + 2
  82. ' bytes for word containing number of node .. :) 
  83. '
  84.  
  85. For A=1 To NODES
  86.    NODE= Extension_17_00B0(8+2,0)
  87.    If NODE
  88.       Doke NODE+8,A
  89.        Extension_17_0064 LIST,NODE
  90.    Else 
  91.       CLEAN_UP
  92.    End If 
  93. Next 
  94.  
  95. End Proc[LIST]